package com.xiaode.controller.app.statistics;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.BooleanV;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.util.Date;

@Path("/statistics")
@Api("统计相关")
@EnableCORS
public class StatisticsController extends Controller {
	@Inject
	private StatisticsService service;

	@ApiOper("月度之星")
	public void monthStar(@ApiPara(value = "rankNum", notes = "排名前几") Integer rankNum,
			@NotEmpty @BooleanV @ApiPara(value = "haveMe", notes = "是否显示个人排名") Boolean haveMe,
			@ApiPara(value = "gradeId", notes = "查询范围年纪，如果添加会覆盖班级参数") Integer gradeId,
			@NotEmpty @Size @ApiPara(value = "date", notes = "要查询的日期") Date date) throws Exception {
		Integer userId = getAttr("userId");
		Integer userType = getAttr("userType");
		Ret ret = service.monthStar(userId, userType, date, gradeId, haveMe, rankNum);
		renderJson(ret);
	}

	@ApiOper("积分排行")
	public void scoreSort(@BooleanV @ApiPara(value = "haveMe", notes = "是否显示个人排名") Boolean haveMe) throws Exception {
		Integer userId = getAttr("userId");
		Integer userType = getAttr("userType");
		Ret ret = service.scoreSort(userId, userType, haveMe);
		renderJson(ret);
	}
	
	
	@ApiOper("积分详情（个人页面中统计积分来源）")
	public void scoreDetails(@NotEmpty @ApiPara(value = "accountId", notes = "账号id") Integer accountId) throws Exception {
		Ret ret = service.scoreDetails(accountId);
		renderJson(ret);
	}
	
	@ApiOper("用户月度之星详情（个人页面中点击积分）")
	public void monthStarDetails(@NotEmpty @ApiPara(value = "accountId", notes = "账号id") Integer accountId) throws Exception {
		Ret ret = service.monthStarDetails(accountId);
		renderJson(ret);
	}

}
